<template>
  <el-card>
    <el-form label-width="120px" :model="addForm">
      <el-form-item label="属性名" prop="specsname">
        <el-input placeholder="请输入属性名" v-model="addForm.specsname"></el-input>
      </el-form-item>
      <el-form-item label="属性值" prop="attrs">
        <div v-for="(item,index) in attrList" :key="index">
            <el-input placeholder="请输入属性值"></el-input>
            <el-button v-if="index==0" type="primary" @click="addAttr">添加</el-button>
            <el-button v-else type="danger" @click="removeAttr(index)">移除</el-button>

        </div>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-radio-group v-model="addForm.status">
          <el-radio :label="1">正常</el-radio>
          <el-radio :label="2">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">立即添加</el-button>
        <el-button>重置</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      addForm: {
        specsname: "", // 规格名称
        attrs: "", // 属性值
        status: 1 // 状态
      },
      attrList:[
          {value:''}
      ]
    };
  },
  methods:{
      addAttr(){
          if(this.attrList.length>=5){
              return this.$error('最多只能添加5个');
          }
          this.attrList.push({value:''});
      },
      removeAttr(index){
          this.attrList.splice(index,1);
      }
  }
};
</script>

<style>
.el-input{
    width: 300px;
    margin-bottom: 4px;
}
</style>